function AccountModel() {
	
	
        var am = this;
        var secur = new Security();
        this.list = new Object();
        this.roles = new Object();
	
        this.getList = function() {
            return this.list;
        },
        
        this.getRoles = function() {
            return this.roles;
        },
        
        this.load = function(callback) {
		$.ajax({
			type: "GET",
			url: "account_list.htm",
			dataType: "json",
			success: function(response) {
				if (response.res == false) {
					alert(response.error);
                    if (response.error == "access_denied") {
                    
                    }
					return;
				}
				
				var tlist = response.list;
				for (var key in tlist) {
					
					var item = {
						id: tlist[key].id,
						fname: tlist[key].firstName,
                                                lname: tlist[key].lastName,
						email: tlist[key].email,
                                                zip: tlist[key].zip,
                                                gender: tlist[key].gender,
                                                roles: tlist[key].roles
					};
                                        
					am.list[tlist[key].id] = item;
				}
                                
                                var rlist = response.roles;
				for (var key in rlist) {
					
					var item = {
						id: rlist[key].id,
						roleValue: rlist[key].roleValue
					};
                                        am.roles[rlist[key].id] = item;
				}
		
				callback(am.list);
			}
		});
	},
	
	this.add = function(row, callback) {
		
		$.ajax({
			type: "POST",
			url: "account_add.htm",
			data: {
                email: row.email, 
                fname: row.fname, 
                lname: row.lname, 
                zip: row.zip, 
                gender: row.gender,
                role: row.role
            },
			dataType: "json",
			success: function(response) {
                if (response.res == "false") {
					alert(response.error);
                    if (response.error == "access_denied") {
                        secur.load(callback, am.addSuccess);
                    }
					return;
				}
				
				am.addSuccess(response, callback);
			}
		});
	},
    
    this.addSuccess = function(response, callback) {
        var item = response.item;
        var obj = new Object();
        obj['id'] = item.id;
        obj['fname'] = item.firstName;
        obj['lname'] = item.lastName;
        obj['email'] = item.email;
        obj['zip'] = item.zip;
        obj['gender'] = item.gender;
        am.list[item.id] = obj;

        callback(obj);
    },
	
	this.edit = function(row, callback) {
		$.ajax({
			type: "POST",
			url: "account_edit.htm",
			data: {
                id: row.id, 
                email: row.email, 
                fname: row.fname, 
                lname: row.lname, 
                zip: row.zip, 
                gender: row.gender,
                role: row.role
            },
			dataType: "json",
			success: function(response) {
                if (response.res == "false") {
					alert(response.error);
                    if (response.error == "access_denied") {
                        secur.load(callback, am.editSuccess);
                    }
					return;
				}
				
				am.editSuccess(response, callback);
			}
		});
	},
    
    this.editSuccess = function(response, callback) {
        var item = response.item;
        var obj = am.list[item.id];
        obj['id'] = item.id;
        obj['fname'] = item.firstName;
        obj['lname'] = item.lastName;
        obj['email'] = item.email;
        obj['zip'] = item.zip;
        obj['gender'] = item.gender;
        am.list[item.id] = obj;

        callback(obj);
    },
	
	this.del = function(id, callback) {
            $.ajax({
                type: "GET",
                url: "account_delete.htm?id="+id,
                dataType: "json",
                success: function(response) {
                    if (response.res == "false") {
                            alert(response.error);
                        if (response.error == "access_denied") {
                            secur.load(callback, am.deleteSuccess);
                        }
                            return;
                    }

                    am.deleteSuccess(response, callback);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert("222")
                  }
            });
	},
    
    this.deleteSuccess = function(response, callback) {
        var tmp = new Object();
        var tlist = am.list;
        for (var key in tlist) {

            if (key == id) {
                continue;
            }

            var item = new Object();
            item['id'] = tlist[key].id;
            item['fname'] = tlist[key].fname;
            item['lname'] = tlist[key].lname;
            item['email'] = tlist[key].email;
            item['zip'] = tlist[key].zip;
            item['gender'] = tlist[key].gender;
            tmp[tlist[key].id] = item;
        }
        am.list = tmp;

        callback(id);
    }
	
}